<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="com.xq.shop.service.admin.ICategoryService"%>
<%@page import="com.xq.shop.util.AdminServiceFactory"%>
<%@page import="com.xq.shop.vo.SearchObject"%>
<%@page import="com.xq.shop.vo.PageInfo"%>
<%@page import="com.xq.shop.po.Category"%>
<%@page import="com.xq.shop.util.SortCategoryBySeq"%>
<%
	ICategoryService service = AdminServiceFactory.getCategoryService();
	PageInfo<Category> result = service.get(new SearchObject(1, 100));
	
	Map<Long, List<Category>> map = new HashMap<Long, List<Category>>();
	for(Category category : result.getPage()){
		
		if(map.get(category.getParent_id()) == null){
			map.put(category.getParent_id(), new ArrayList<Category>());				
		}
		map.get(category.getParent_id()).add(category);
	}
	
	if(map.get(0L) != null){
		
		List<Category> grade1_List = map.get(0L);
		Collections.sort(grade1_List, new SortCategoryBySeq());
		int i = 1;
		for(Category grade1 : grade1_List){
%>
		<dl <%=(i++ == grade1_List.size()) ? "class='last'" : ""%>>
			<dt><a href="#"><%=grade1.getName() %></a></dt>
			<%
				if(map.get(grade1.getId()) == null){
					continue;
				}
				
				List<Category> grade2_List = map.get(grade1.getId());
				Collections.sort(grade2_List, new SortCategoryBySeq());
				for(Category grade2 : grade2_List){
			%>
				<dd><a href="#"><%=grade2.getName() %></a></dd>
			<%
				}
			%>
		</dl>
<%	 	}
	}
%>